package core.report.yearReport.bean;

import org.springframework.jdbc.support.rowset.SqlRowSet;

import com.yalu.common.Constant;

import core.report.yearReport.util.ExportExcelUtil;

public abstract class SalesReportDataBean extends BaseExcelReportDataBean{
	protected String name;
	protected int shopId;
	protected String shopName;
	protected int attribute_id;
	
	protected double totalAmount;
	protected double sale_accomplish;
	protected double sale_rate;
	protected double cost_Amount;
	protected double cost_rate;
	protected double cost_accomplish;
	protected long views;
	protected double guests;
	protected double success_rate;
	
	
	public abstract void addProperties(SalesReportDataBean data);

	public abstract String getValueByIndex(int index);

	public int getFormatTypeByIndex(int index){
			switch (index) {
			case 0:
				return ExportExcelUtil.TEXT_TYPE;
			case 1:
				return ExportExcelUtil.LONG_TYPE;
			case 2:
				return ExportExcelUtil.PERCENT_TYPE;
			case 3:
				return ExportExcelUtil.PERCENT_TYPE;
			case 4:
				return ExportExcelUtil.LONG_TYPE;
			case 5:
				return ExportExcelUtil.PERCENT_TYPE;
			case 6:
				return ExportExcelUtil.PERCENT_TYPE;
			case 7:
				return ExportExcelUtil.LONG_TYPE;
			case 8:
				return ExportExcelUtil.DECIMAL_TYPE;
			case 9:
				return ExportExcelUtil.PERCENT_TYPE;
			case 10:
				return ExportExcelUtil.DECIMAL_TYPE;
			case 11:
				return ExportExcelUtil.DECIMAL_TYPE;
			default:
				return ExportExcelUtil.TEXT_TYPE;
			}
	}

	public void subtract(int count) {
		if(count!=0){
			this.setSale_accomplish(this.getSale_accomplish() / count);
			this.setSale_rate(this.getSale_rate() / count);
			this.setCost_rate(this.getCost_rate() / count);
			this.setCost_accomplish(this.getCost_accomplish() / count);
			this.setSuccess_rate(this.getSuccess_rate() / count);
		}else{
			this.setSale_accomplish(0);
			this.setSale_rate(0);
			this.setCost_rate(0);
			this.setCost_accomplish(0);
			this.setSuccess_rate(0);
		}
	}

	public static SalesReportDataBean createSalesReportDataBeanByDateType(
			String dateType) {
		SalesReportDataBean bean = null;
		if (dateType.equals(Constant.WEEK_STRING)) {
			bean = new WeekSalesReportDataBean();
		} else if (dateType.equals(Constant.MONTH_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		} else if (dateType.equals(Constant.YEAR_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		}else if (dateType.equals(Constant.LAST_WEEK_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		}else if (dateType.equals(Constant.LAST_YEAR_THIS_WEEK_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		}else if (dateType.equals(Constant.LAST_MONTH_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		}else if (dateType.equals(Constant.LAST_YEAR_THIS_MONTH_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		}else if (dateType.equals(Constant.LAST_YEAR_STRING)) {
			bean = new YearOrMonthOrWeekSalesReportDataBean();
		}else if (dateType.equals(Constant.LAST_YEAR_THIS_CUSTOM_STRING)) {
			bean = new CustomSalesReportDataBean();
		} 
		return bean;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getShopId() {
		return shopId;
	}

	public void setShopId(int shopId) {
		this.shopId = shopId;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public int getAttribute_id() {
		return attribute_id;
	}

	public void setAttribute_id(int attribute_id) {
		this.attribute_id = attribute_id;
	}

	public abstract void setProperties(SqlRowSet rs);

	public double getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(double totalAmount) {
		this.totalAmount = totalAmount;
	}

	public double getSale_accomplish() {
		return sale_accomplish;
	}

	public void setSale_accomplish(double sale_accomplish) {
		this.sale_accomplish = sale_accomplish;
	}

	public double getSale_rate() {
		return sale_rate;
	}

	public void setSale_rate(double sale_rate) {
		this.sale_rate = sale_rate;
	}

	public double getCost_Amount() {
		return cost_Amount;
	}

	public void setCost_Amount(double cost_Amount) {
		this.cost_Amount = cost_Amount;
	}

	public double getCost_rate() {
		return cost_rate;
	}

	public void setCost_rate(double cost_rate) {
		this.cost_rate = cost_rate;
	}

	public double getCost_accomplish() {
		return cost_accomplish;
	}

	public void setCost_accomplish(double cost_accomplish) {
		this.cost_accomplish = cost_accomplish;
	}

	public long getViews() {
		return views;
	}

	public void setViews(long views) {
		this.views = views;
	}

	public double getGuests() {
		return guests;
	}

	public void setGuests(double guests) {
		this.guests = guests;
	}

	public double getSuccess_rate() {
		return success_rate;
	}

	public void setSuccess_rate(double success_rate) {
		this.success_rate = success_rate;
	}

	public int compareTo(BaseExcelReportDataBean baseBean) {
		SalesReportDataBean otherBean = (SalesReportDataBean)baseBean;
			if(this.getAttribute_id()==0){//无attributeId 合计的
				return 1;
			}
			if(otherBean.getAttribute_id()==0){//无attributeId 合计的
				return -1;
			}
			
			if(this.getAttribute_id()>otherBean.getAttribute_id()){//按attributeId从小到大排列
					return 1;
			}else if(this.getAttribute_id()<otherBean.getAttribute_id()){
				return -1;
			}else{
				if(this.getShopId()==0){
					return 1;
				}
				if(otherBean.getShopId()==0){
					return -1;
				}
				if(this.getShopId()>otherBean.getShopId()){//按ShopId从小到大排列
					return 1;
				}else if(this.getShopId()<otherBean.getShopId()){
					return -1;
				}
			}
		return 0;
	}
}
